package com.netty.io.nio;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.ReadableByteChannel;

/**
 *
 *使用nio自带的方法快速复制文件
 * */
public class NioCopy2Example {

    public static void main(String[] args) throws Exception{
        File file = new File("/Users/xiaoqi/nio3.txt");
        FileInputStream inputStream = new FileInputStream(file);
        FileOutputStream outputStream = new FileOutputStream("/Users/xiaoqi/nio4.txt");
        FileChannel inputStreamChannel = inputStream.getChannel();
        FileChannel outputStreamChannel = outputStream.getChannel();

        outputStreamChannel.transferFrom(inputStreamChannel,0,inputStreamChannel.size());
        outputStreamChannel.close();
        inputStreamChannel.close();
        inputStream.close();
        outputStream.close();
    }
}
